//
//  AppDelegate.m
//  DianBa
//
//  Created by karl on 2018/8/20.
//  Copyright © 2018年 DianBa. All rights reserved.
//

#import "AppDelegate.h"
#import "DBTabBarViewController.h"
#import "DBLaunchViewController.h"
#import "DBLaunchScrollViewController.h"

@interface AppDelegate ()<LaunchDelegate,LaunchScrollDelegate,UITabBarControllerDelegate>

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    DBLaunchViewController *launchViewControll = [[DBLaunchViewController alloc]init];
    [launchViewControll setDelegate:self];
    self.window.rootViewController = launchViewControll;
    [self setNavBarAppearence];
    [self keyboardSetting];
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)setNavBarAppearence{
    // 设置是 广泛使用WRNavigationBar，还是局部使用WRNavigationBar，目前默认是广泛使用
    [WRNavigationBar wr_widely];
    [WRNavigationBar wr_setBlacklist:@[]];
    
    // 设置导航栏默认的背景颜色
    [WRNavigationBar wr_setDefaultNavBarBarTintColor:[UIColor colorWithString:MAIN_COLOR]];
    // 设置导航栏所有按钮的默认颜色
    [WRNavigationBar wr_setDefaultNavBarTintColor:[UIColor whiteColor]];
    // 设置导航栏标题默认颜色
    [WRNavigationBar wr_setDefaultNavBarTitleColor:[UIColor whiteColor]];
    // 统一设置状态栏样式
    [WRNavigationBar wr_setDefaultStatusBarStyle:UIStatusBarStyleLightContent];
    // 如果需要设置导航栏底部分割线隐藏，可以在这里统一设置
    [WRNavigationBar wr_setDefaultNavBarShadowImageHidden:YES];
}

-(void)keyboardSetting{
    IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager]; // 获取类库的单例变量
    keyboardManager.enable = YES; // 控制整个功能是否启用
    keyboardManager.shouldResignOnTouchOutside = YES; // 控制点击背景是否收起键盘
    keyboardManager.shouldToolbarUsesTextFieldTintColor = YES; // 控制键盘上的工具条文字颜色是否用户自定义
    keyboardManager.toolbarManageBehaviour = IQAutoToolbarBySubviews; // 有多个输入框时，可以通过点击Toolbar 上的“前一个”“后一个”按钮来实现移动到不同的输入框
    keyboardManager.enableAutoToolbar = YES; // 控制是否显示键盘上的工具条
    keyboardManager.shouldShowToolbarPlaceholder = YES; // 是否显示占位文字
    keyboardManager.placeholderFont = [UIFont boldSystemFontOfSize:17]; // 设置占位文字的字体
    keyboardManager.keyboardDistanceFromTextField = 10.0f; // 输入框距离键盘的距离
}

#pragma mark - 清除堆栈
- (void)do_clear_controllers{     // 清除多余的controller，用于退出登录。。。
    for (UIView *aView in [self.window subviews]) {
        [aView removeFromSuperview];
    }
    self.window.rootViewController = nil;
}

#pragma mark - LaunchDelegate
//进入引导页
-(void)launchEnterScrollViewController{
    [self do_clear_controllers];
    DBLaunchScrollViewController *scrollController = [[DBLaunchScrollViewController alloc]init];
    [scrollController setDelegate:self];
    self.window.rootViewController = scrollController;
}

//进入首页
-(void)launchEnterHomeViewController{
    [self do_clear_controllers];
    DBTabBarViewController *tabBarController = [[DBTabBarViewController alloc]init];
    tabBarController.delegate = self;
    self.window.rootViewController = tabBarController;
}

#pragma mark - UITabBarControllerDelegate
- (BOOL)tabBarController:(UITabBarController*)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    // 记录之前选择的selectedIndex
    return YES;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if (tabBarController.selectedIndex == 1 || tabBarController.selectedIndex == 2) {
//        if (![FHConstantModel sharedInstanced].isLogin) {
//            tabBarController.selectedIndex = self.oldSelectIndex;
//            [[FHLoginManager shareInstance] showLoginViewController];
//        }
    }
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
